﻿using System;
using System.Collections.Generic;
using System.Xml.Linq;
using Common.Interface;
using EntityFrameworkExtension.Interface;
using MainProcessor.Processors;
using MainProcessor.Validation;
using NUnit.Framework;
using Rhino.Mocks;

namespace Test.Main.Validation
{
    [TestFixture]
    public class ShareClassValidationTests
    {
        private IValidateInput shareClassValidation;
        private IEntityFactory entityFactory;
        private IEntityFactory concreteEntityFactory;
        private List<IChild> children;

        [SetUp]
        public void SetUp()
        {
            entityFactory = MockRepository.GenerateMock<IEntityFactory>();
            concreteEntityFactory = new EntityFactory();
            shareClassValidation = new ChildValidation(entityFactory);
        }

        [TearDown]
        public void Teardown()
        {
            entityFactory.VerifyAllExpectations();
        }

        [Test]
        public void MessageContainsMoreThanOneIsMasterThenShouldReturnError()
        {
            var xmlMessage = XElement.Parse(ConstantXml.TestString.Replace("<IsMaster>False</IsMaster>", "<IsMaster>True</IsMaster>"));

            children = concreteEntityFactory.CreateChildren(xmlMessage);
            entityFactory.Expect(x => x.CreateChildren(null)).IgnoreArguments().Return(children);

            string result = shareClassValidation.Validate(xmlMessage);

            Assert.That(result.Length, Is.GreaterThan(0));
        }

        [Test]
        public void MessageContainsnonGuidTypeheimdallGuidThenShouldReturnError()
        {
            var xmlMessage = XElement.Parse(ConstantXml.TestString.Replace("<ChildGuid>720d3c24-3fe9-4ce1-ae5c-a6a7b949c773</ChildGuid>", "<ChildGuid>12345</ChildGuid>"));

            children = concreteEntityFactory.CreateChildren(xmlMessage);
            entityFactory.Expect(x => x.CreateChildren(null)).IgnoreArguments().Return(children);

            string result = shareClassValidation.Validate(xmlMessage);

            Assert.That(result.Length, Is.GreaterThan(0));
        }
    }
        
}
 